// File Name: oled_logic.c
// Author: kukukukuku~
// Date: 2024-07-04

#include "./User/ADC/inc/adc_ctrl.h"
#include "./User/Flash/inc/flash_ctrl.h"
#include "./User/Key/inc/key_ctrl.h"
#include "./User/LED/inc/led_logic.h"
#include "./User/OLED/inc/oled_font.h"
#include "./User/OLED/inc/oled_logic.h"
#include "./User/RS485/inc/rs485_ctrl.h"
#include "./User/Step_Motor/inc/step_motor_logic.h"
#include "./User/Sys/inc/init.h"
#include "./User/WS2812B/inc/ws2812b_ctrl.h"
#include "stdio.h"
#include "string.h"

static uint16_t temp = 0xFFFF;  //临时变量
static uint8_t str[32]; //临时字符串

/**
 * @brief   OLED设置坐标
 * @param   x:  横坐标
 * @param   y:  纵坐标
 * @retval  None
 * @note    None
*/
void oled_set_position(uint8_t x, uint8_t y)
{
    //限制可显示范围
    if(x > OLED_COLUMN_MAX - 8)
    {
        x = OLED_COLUMN_MAX - 8;
    }
    if(y > OLED_PAGE_MAX - 1)
    {
        y = OLED_PAGE_MAX - 1;
    }
    
    oled_iic_send_data(0xB0 + y, OLED_SEND_CMD);
    oled_iic_send_data((x & 0xF0) >> 4 | 0x10, OLED_SEND_CMD);
    oled_iic_send_data(x & 0x0F, OLED_SEND_CMD);
}


/**
 * @brief   OLED开启显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_display_on(void)
{
    oled_iic_send_data(0x8D, OLED_SEND_CMD);
    oled_iic_send_data(0x14, OLED_SEND_CMD);
    oled_iic_send_data(0xAF, OLED_SEND_CMD);
}


/**
 * @brief   OLED关闭显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_display_off(void)
{
    oled_iic_send_data(0x8D, OLED_SEND_CMD);
    oled_iic_send_data(0x10, OLED_SEND_CMD);
    oled_iic_send_data(0xAE, OLED_SEND_CMD);
}


/**
 * @brief   OLED清除屏幕
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_clear(void)
{
    for(uint8_t i = 0; i < OLED_PAGE_MAX; i++)
    {
        oled_iic_send_data(0xB0+i, OLED_SEND_CMD);
        oled_iic_send_data(0x00, OLED_SEND_CMD);
        oled_iic_send_data(0x10, OLED_SEND_CMD);
        for(uint8_t j = 0; j < OLED_COLUMN_MAX; j++)
        {
            oled_iic_send_data(0x00, OLED_SEND_DATA);
        }
    }
}


/**
 * @brief   OLED显示一个8x16字符
 * @param   x:          横坐标
 * @param   y:          纵坐标
 * @param   ch:         要显示的字符
 * @param   mode:       显示模式
 * 0:   正相
 * 1:   反相
 * @retval  None
 * @note    None
*/
void oled_show_char_8x16(uint8_t x, uint8_t y, uint8_t ch, uint8_t mode)
{
    if(ch > 127)
    {
        ch = 127;
    }
    
    //限制坐标
    if(x > OLED_COLUMN_MAX - 8)
    {
        x = 0;
        y += 2;
    }
    if(y > OLED_PAGE_MAX - 2)
    {
        y = 0;
    }
    
    //一个字符占两页
    for(uint8_t i = 0; i < 2; i++)
    {
        oled_set_position(x, y + i);
        
        //一个字符在每页占8列
        for(uint8_t j = 0; j < 8; j++)
        {
            mode ?\
            oled_iic_send_data(~oledFont8x16[ch * 16 + (8 * i) + j], OLED_SEND_DATA) :\
            oled_iic_send_data(oledFont8x16[ch * 16 + (8 * i) + j], OLED_SEND_DATA);
        }
    }
}


/**
 * @brief   OLED显示8x16字符串
 * @param   x:          横坐标
 * @param   y:          纵坐标
 * @param   str:        要显示的字符串
 * @param   mode:       显示模式
 * 0:   正相
 * 1:   反相
 * @retval  None
 * @note    None
*/
void oled_show_str_8x16(uint8_t x, uint8_t y, const uint8_t * const str, uint8_t mode)
{
    uint32_t i = 0;
    
    if(str == NULL)
    {
        return;
    }
    
    while(str[i])
    {
        //限制坐标
        if(x > OLED_COLUMN_MAX - 8)
        {
            x = 0;
            y += 2;
        }
        if(y > OLED_PAGE_MAX - 2)
        {
            y = 0;
        }
        
        oled_show_char_8x16(x, y, str[i++], mode);
        
        x += 8;
    }
}


/**
 * @brief   OLED显示16x16中文
 * @param   x:              横坐标
 * @param   y:              纵坐标
 * @param   oledFontSource: 字库源
 * @param   oledFontNum:    中文字符个数
 * @param   mode:           显示模式
 * 0:   正相
 * 1:   反相
 * @retval  None
 * @note    None
*/
void oled_show_chinese_16x16(uint8_t x, uint8_t y, const uint8_t *oledFontSource, uint8_t oledFontNum, uint8_t mode)
{
    for(uint8_t i = 0; i < oledFontNum; i++)
    {
        //限制坐标
        if(x > OLED_COLUMN_MAX - 16)
        {
            x = 0;
            y += 2;
        }
        if(y > OLED_PAGE_MAX - 2)
        {
            y = 0;
        }
        
        //一个字符占两页
        for(uint8_t j = 0; j < 2; j++)
        {
            oled_set_position(x, y + j);
            
            //一个字符在每页占16列
            for(uint8_t k = 0; k < 16; k++)
            {
                mode ?\
                oled_iic_send_data(~oledFontSource[32 * i + (16 * j) + k], OLED_SEND_DATA) :\
                oled_iic_send_data(oledFontSource[32 * i + (16 * j) + k], OLED_SEND_DATA);
            }
        }
        
        x += 16;
    }
}


/**
 * @brief   OLED显示主界面
 * @param   mainId: 界面编号
 * @retval  None
 * @note    None
*/
void oled_dis_main(uint8_t mainId)
{
    static uint8_t str[32];
    
    memset(str, 0, sizeof(str));
    
    switch(mainId)
    {
        case 0:
            oled_show_str_8x16(0, 0, (uint8_t *)"Key click beep", 0);
            sprintf((char *)str, "%u", keyClickBeep);
            break;
        case 1:
            oled_show_str_8x16(0, 0, (uint8_t *)"Key long beep", 0);
            sprintf((char *)str, "%u", keyLongBeep);
            break;
        case 2:
            oled_show_str_8x16(0, 0, (uint8_t *)"LED1 mode", 0);
            led1.mode == LED_MODE_BREATH ? sprintf((char *)str, "breath") : sprintf((char *)str, "blink");
            break;
        case 3:
            oled_show_str_8x16(0, 0, (uint8_t *)"LED1 breath step", 0);
            sprintf((char *)str, "%u", led1.breathStep);
            break;
        case 4:
            oled_show_str_8x16(0, 0, (uint8_t *)"LED1 blink freq", 0);
            sprintf((char *)str, "%u", led1.blinkNum);
            break;
        case 5:
            oled_show_str_8x16(0, 0, (uint8_t *)"LED2 mode", 0);
            led2.mode == LED_MODE_BREATH ? sprintf((char *)str, "breath") : sprintf((char *)str, "blink");
            break;
        case 6:
            oled_show_str_8x16(0, 0, (uint8_t *)"LED2 breath step", 0);
            sprintf((char *)str, "%u", led2.breathStep);
            break;
        case 7:
            oled_show_str_8x16(0, 0, (uint8_t *)"LED2 blink freq", 0);
            sprintf((char *)str, "%u", led2.blinkNum);
            break;
        case 8:
            oled_show_str_8x16(0, 0, (uint8_t *)"OLED dir", 0);
            oledDir ? sprintf((char *)str, "reverse") : sprintf((char *)str, "normal");
            break;
        case 9:
            oled_show_str_8x16(0, 0, (uint8_t *)"OLED light", 0);
            if(oledLightLevel == 0)
                sprintf((char *)str, "high");
            else if(oledLightLevel == 1)
                sprintf((char *)str, "middle");
            else if(oledLightLevel == 2)
                sprintf((char *)str, "low");
            break;
        case 10:
            oled_show_str_8x16(0, 0, (uint8_t *)"OLED cursor", 0);
            if(oledCursorStyle == 0)
                sprintf((char *)str, "reverse");
            else if(oledCursorStyle == 1)
                sprintf((char *)str, ">");
            else if(oledCursorStyle == 2)
                sprintf((char *)str, "*");
            else if(oledCursorStyle == 3)
                sprintf((char *)str, "@");
            else if(oledCursorStyle == 4)
                sprintf((char *)str, "->");
            else if(oledCursorStyle == 5)
                sprintf((char *)str, "<-");
            else if(oledCursorStyle == 6)
                sprintf((char *)str, "[ ]");
            break;
        case 11:
            oled_show_str_8x16(0, 0, (uint8_t *)"OLED refresh ms", 0);
            sprintf((char *)str, "%u", oledMainPageRefreshInterval);
            break;
        case 12:
            oled_show_str_8x16(0, 0, (uint8_t *)"OLED menu number", 0);
            oledMenuNumberFlag ? sprintf((char *)str, "blank") : sprintf((char *)str, "show");
            break;
        case 13:
            oled_show_str_8x16(0, 0, (uint8_t *)"RS485 ID", 0);
            sprintf((char *)str, "%#04x", rs485Id);
            break;
        case 14:
            oled_show_str_8x16(0, 0, (uint8_t *)"RS485 mode", 0);
            rs485Mode == 0 ? sprintf((char *)str, "active") : sprintf((char *)str, "passive");
            break;
        case 15:
            oled_show_str_8x16(0, 0, (uint8_t *)"RS485 baudrate", 0);
            sprintf((char *)str, "%u", rs485UsartBaudRate);
            break;
        case 16:
            oled_show_str_8x16(0, 0, (uint8_t *)"Step motor state", 0);
            if(stepMotorState == STEP_MOTOR_STOP)
                sprintf((char *)str, "stop");
            else if(stepMotorState == STEP_MOTOR_CW)
                sprintf((char *)str, "cw");
            else if(stepMotorState == STEP_MOTOR_CCW)
                sprintf((char *)str, "ccw");
            break;
        case 17:
            oled_show_str_8x16(0, 0, (uint8_t *)"Step motor mode", 0);
            if(stepMotorMode == FULL_STEP)
                sprintf((char *)str, "full");
            else if(stepMotorMode == HALF_STEP)
                sprintf((char *)str, "half");
            else if(stepMotorMode == QUARTER_STEP)
                sprintf((char *)str, "quarter");
            else if(stepMotorMode == EIGHTH_STEP)
                sprintf((char *)str, "eighth");
            else if(stepMotorMode == SIXTEENTH_STEP)
                sprintf((char *)str, "sixteenth");
            break;
        case 18:
            oled_show_str_8x16(0, 0, (uint8_t *)"Step motor speed", 0);
            if(stepMotorSpd == 0)
                sprintf((char *)str, "ultra-fast");
            else if(stepMotorSpd == 1)
                sprintf((char *)str, "fast");
            else if(stepMotorSpd == 2)
                sprintf((char *)str, "normal");
            else if(stepMotorSpd == 3)
                sprintf((char *)str, "low");
            else if(stepMotorSpd == 4)
                sprintf((char *)str, "ultra-low");
            break;
        case 19:
            oled_show_str_8x16(0, 0, (uint8_t *)"Temperature", 0);
            sprintf((char *)str, "%2u.%2u", (uint32_t)temperature, (uint32_t)(temperature * 100) % 100);
            break;
        case 20:
            oled_show_str_8x16(0, 0, (uint8_t *)"Version", 0);
            sprintf((char *)str, "v%u.%u.%u", VERSION_MAIN, VERSION_SECOND, VERSION_PHASE);
            break;
        case 21:
            oled_show_str_8x16(0, 0, (uint8_t *)"WS2812B stop rgb", 0);
            sprintf((char *)str, "0x%06x", ws2812bStopRed << 16 | ws2812bStopGreen << 8 | ws2812bStopBlue);
            break;
        case 22:
            oled_show_str_8x16(0, 0, (uint8_t *)"WS2812B cw rgb", 0);
            sprintf((char *)str, "0x%06x", ws2812bCwRed << 16 | ws2812bCwGreen << 8 | ws2812bCwBlue);
            break;
        case 23:
            oled_show_str_8x16(0, 0, (uint8_t *)"WS2812B ccw rgb", 0);
            sprintf((char *)str, "0x%06x", ws2812bCcwRed << 16 | ws2812bCcwGreen << 8 | ws2812bCcwBlue);
            break;
        case 24:
            oled_show_str_8x16(0, 0, (uint8_t *)"WS2812B cw mode", 0);
            ws2812bCwMode == 0 ? sprintf((char *)str, "random") : sprintf((char *)str, "fixed");
            break;
        case 25:
            oled_show_str_8x16(0, 0, (uint8_t *)"WS2812B ccw mode", 0);
            ws2812bCcwMode == 0 ? sprintf((char *)str, "random") : sprintf((char *)str, "fixed");
            break;
        default:
            break;
    }
    
    oled_show_str_8x16(0, 2, str, 0);
    
    if(keyLockFlag)
    {
        oled_show_char_8x16(120, 2, 'L', 1);
    }
}


/**
 * @brief   OLED显示菜单
 * @param   oledMenu:   菜单对象
 * @retval  选中的菜单
 * @note    None
*/
uint8_t oled_dis_menu(pOledMenu oledMenu)
{
    uint8_t ret = 0xFF;
    
    static uint8_t indexStr[10];
    
    oledItemUpDnEnaFlag = 1;
    
    //选项上移
    if(oledItemUpFlag)
    {
        if(oledMenu->itemIndex > 0)
        {
            --oledMenu->itemIndex;
        }
        
        if(oledMenu->oledRowIndex > 0)
        {
            --oledMenu->oledRowIndex;
        }
        
        oledItemUpFlag = 0;
    }
    
    //选项下移
    if(oledItemDnFlag)
    {
        if(oledMenu->itemIndex < oledMenu->itemNum-1)
        {
            ++oledMenu->itemIndex;
        }
        
        if(oledMenu->oledRowIndex < 1 && oledMenu->oledRowIndex < oledMenu->itemIndex)
        {
            ++oledMenu->oledRowIndex;
        }
        
        oledItemDnFlag = 0;
    }
    
    //选项确认
    if(oledItemSelectFlag)
    {
        if(oledMenu->itemIndex == oledMenu->itemNum-1)
        {
            if(oledMenuLevel > 0)
            {
                --oledMenuLevel;
            }
            else
            {
                oledDisModeFlag = 0;
            }
        }
        else
        {
            if(oledMenu->item[oledMenu->itemIndex].nextLevelFlag)
            {
                ++oledMenuLevel;
            }
            else
            {
                if(oledMenuLevel > 0)
                {
                    --oledMenuLevel;
                }
            }
        }
        
        ret = oledMenu->itemIndex;
        oledMenu->itemIndex = oledMenu->oledRowIndex = 0;
        oledMenu->itemIndexLast = oledMenu->oledRowIndexLast = -1;
        
        oledItemUpDnEnaFlag = 0;
        oledItemSelectFlag = 0;
        oled_clear();
        
        return ret;
    }
    
    if(oledMenu->itemIndexLast != oledMenu->itemIndex || oledMenu->oledRowIndexLast != oledMenu->oledRowIndex)
    {
        oled_clear();
        oledMenu->itemIndexLast = oledMenu->itemIndex;
        oledMenu->oledRowIndexLast = oledMenu->oledRowIndex;
    }
    
    switch(oledCursorStyle)
    {
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_1_INDEX:
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, oledMenu->oledRowIndex == 0 ? 1 : 0);
            break;
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_2_INDEX:
            oledMenu->oledRowIndex == 0 ?(\
            oled_show_str_8x16(8, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0),\
            oled_show_char_8x16(0, 0, '>', 0)) :\
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0);
            break;
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_3_INDEX:
            oledMenu->oledRowIndex == 0 ?(\
            oled_show_str_8x16(8, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0),\
            oled_show_char_8x16(0, 0, '*', 0)) :\
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0);
            break;
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_4_INDEX:
            oledMenu->oledRowIndex == 0 ?(\
            oled_show_str_8x16(8, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0),\
            oled_show_char_8x16(0, 0, '@', 0)) :\
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0);
            break;
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_5_INDEX:
            oledMenu->oledRowIndex == 0 ?(\
            oled_show_str_8x16(16, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0),\
            oled_show_str_8x16(0, 0, (uint8_t *)"->", 0)) :\
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0);
            break;
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_6_INDEX:
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0);
            oledMenu->oledRowIndex == 0 ? oled_show_str_8x16(strlen((char *)oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName) * 8, 0, (uint8_t *)"<-", 0) : 0;
            break;
        case OLED_LEVEL3_OLED_CURSOR_SYTLE_7_INDEX:
            oledMenu->oledRowIndex == 0 ?(\
            oled_show_str_8x16(8, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0),\
            oled_show_char_8x16(0, 0, '[', 0),\
            oled_show_char_8x16(strlen((char *)oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName) * 8 + 8, 0, ']', 0)) :\
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, 0);
            break;
        default:
            oled_show_str_8x16(0, 0, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex].itemName, oledMenu->oledRowIndex == 0 ? 1 : 0);
            break;
    }
    
    if(oledMenu->itemNum > 1)
    {
        switch(oledCursorStyle)
        {
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_1_INDEX:
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, oledMenu->oledRowIndex == 0 ? 0 : 1);
                break;
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_2_INDEX:
                oledMenu->oledRowIndex == 1 ?(\
                oled_show_str_8x16(8, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0),\
                oled_show_char_8x16(0, 2, '>', 0)) :\
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0);
                break;
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_3_INDEX:
                oledMenu->oledRowIndex == 1 ?(\
                oled_show_str_8x16(8, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0),\
                oled_show_char_8x16(0, 2, '*', 0)) :\
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0);
                break;
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_4_INDEX:
                oledMenu->oledRowIndex == 1 ?(\
                oled_show_str_8x16(8, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0),\
                oled_show_char_8x16(0, 2, '@', 0)) :\
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0);
                break;
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_5_INDEX:
                oledMenu->oledRowIndex == 1 ?(\
                oled_show_str_8x16(16, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0),\
                oled_show_str_8x16(0, 2, (uint8_t *)"->", 0)) :\
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0);
                break;
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_6_INDEX:
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0);
                oledMenu->oledRowIndex == 1 ? oled_show_str_8x16(strlen((char *)oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName) * 8, 2, (uint8_t *)"<-", 0) : 0;
                break;
            case OLED_LEVEL3_OLED_CURSOR_SYTLE_7_INDEX:
                oledMenu->oledRowIndex == 1 ?(\
                oled_show_str_8x16(8, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0),\
                oled_show_char_8x16(0, 2, '[', 0),\
                oled_show_char_8x16(strlen((char *)oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName) * 8 + 8, 2, ']', 0)) :\
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, 0);
                break;
            default:
                oled_show_str_8x16(0, 2, oledMenu->item[oledMenu->itemIndex-oledMenu->oledRowIndex+1].itemName, oledMenu->oledRowIndex == 0 ? 0 : 1);
                break;
        }
    }
    
    if(oledMenuNumberFlag == 0)
    {
        memset(indexStr, 0, sizeof(indexStr));
        sprintf((char *)indexStr, "%2u", oledMenu->itemIndex + 1);
        oled_show_str_8x16(OLED_COLUMN_MAX - 2 * 8, OLED_PAGE_MAX - 2, indexStr, 0);
    }
    
    return ret;
}


/**
 * @brief   计算一个数有多少位十进制
 * @param   val:    要计算的数
 * @retval  计算结果
 * @note    静态函数
*/
static uint8_t get_value_num(uint16_t val)
{
    uint8_t num = 0;
    
    if(val == 0)
    {
        return 1;
    }
    
    while(val)
    {
        num++;
        val /= 10;
    }
    
    return num;
}


/**
 * @brief   OLED设置数值
 * @param   title:      标题
 * @param   currentVal: 当前值
 * @param   minVal:     最小值
 * @param   maxVal:     最大值
 * @retval  要设置的值
 * - 0xFFFF:            无效值
 * - other:             有效值
 * @note    None
*/
uint16_t oled_set_val(const uint8_t * const title, const uint16_t currentVal, const uint16_t minVal, const uint16_t maxVal)
{
    uint16_t ret = 0;
    
    static uint8_t oledValSubStep = 1;  //数值减步进
    static uint8_t oledValPlusStep = 1; //数值加步进
    static uint8_t tempValNum;      //数值位数
    static uint8_t tempValNumLast;  //数值上一次位数
    static uint8_t oledValStepAddFlag;  //数值加减步进增加标志
    
    if(title == NULL || minVal >= maxVal)
    {
        return 0xFFFF;
    }
    
    if(temp == 0xFFFF)
    {
        temp = currentVal;
        tempValNum = tempValNumLast = get_value_num(temp);
        oledValStepAddFlag = temp / 10 % 10;
    }
    
    oledValSetEnaFlag = 1;
    
    //数值单次减小
    if(oledValSetSubFlag)
    {
        if(temp > minVal)
        {
            --temp;
            
            //数值位数发生改变，清屏更新显示坐标
            if((tempValNum = get_value_num(temp)) != tempValNumLast)
            {
                tempValNumLast = tempValNum;
                oled_clear();
            }
        }
        
        oledValSetSubFlag = 0;
    }
    //数值持续减小
    else if(key[KEY_LEFT_INDEX].state == KEY_STATE_CLICK_LONG)
    {
        if(temp >= minVal + oledValSubStep)
        {
            temp -= oledValSubStep;
        }
        else if(temp > minVal)
        {
            --temp;
        }
        
        if((tempValNum = get_value_num(temp)) != tempValNumLast)
        {
            tempValNumLast = tempValNum;
            oled_clear();
        }
        
        if(temp / 100 % 10 != oledValStepAddFlag)
        {
            oledValStepAddFlag = temp / 10 % 10;
            if(oledValSubStep < 0xFF)
                oledValSubStep++;
        }
    }
    else
    {
        oledValSubStep = 1;
    }
    
    //数值单次增大
    if(oledValSetPlusFlag)
    {
        if(temp < maxVal)
        {
            ++temp;
            
            //数值位数发生改变，清屏更新显示坐标
            if((tempValNum = get_value_num(temp)) != tempValNumLast)
            {
                tempValNumLast = tempValNum;
                oled_clear();
            }
        }
        
        oledValSetPlusFlag = 0;
    }
    //数值持续增大
    else if(key[KEY_RIGHT_INDEX].state == KEY_STATE_CLICK_LONG)
    {
        if(maxVal >= oledValPlusStep && temp <= maxVal - oledValPlusStep)
        {
            temp += oledValPlusStep;
        }
        else if(temp < maxVal)
        {
            ++temp;
        }
        
        if((tempValNum = get_value_num(temp)) != tempValNumLast)
        {
            tempValNumLast = tempValNum;
            oled_clear();
        }
        
        if(temp / 100 % 10 != oledValStepAddFlag)
        {
            oledValStepAddFlag = temp / 10 % 10;
            if(oledValPlusStep < 0xFF)
                oledValPlusStep++;
        }
    }
    else
    {
        oledValPlusStep = 1;
    }
    
    //数值确定
    if(oledItemSelectFlag)
    {
        oledItemSelectFlag == 1 ? (ret = temp) : (ret = 0xFFFF);
        temp = 0xFFFF;
        
        oledValSetEnaFlag = 0;
        oledItemSelectFlag = 0;
        
        if(oledMenuLevel > 0)
        {
            oledMenuLevel--;
        }
        
        oled_clear();
        
        return ret;
    }
    
    memset(str, 0, sizeof(str));
    sprintf((char *)str, "%u", temp);
    
    oled_show_str_8x16(0, 0, title, 0);
    
    oled_show_char_8x16(0, OLED_PAGE_MAX - 2, '<', 0);
    oled_show_char_8x16(OLED_COLUMN_MAX - 8, OLED_PAGE_MAX - 2, '>', 0);
    
    if(temp < 10)
        oled_show_str_8x16((OLED_COLUMN_MAX - 1 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else if(temp < 100)
        oled_show_str_8x16((OLED_COLUMN_MAX - 2 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else if(temp < 1000)
        oled_show_str_8x16((OLED_COLUMN_MAX - 3 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else if(temp < 10000)
        oled_show_str_8x16((OLED_COLUMN_MAX - 4 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    else
        oled_show_str_8x16((OLED_COLUMN_MAX - 5 * 8) / 2, OLED_PAGE_MAX - 2, str, 1);
    
    return 0xFFFF;
}


/**
 * @brief   OLED Key三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_key(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //按键短按蜂鸣时间
        case OLED_LEVEL2_KEY_CLICK_BEEP_INDEX:
            {
                uint16_t temp = oled_set_val(oledMenuKey.item[OLED_LEVEL2_KEY_CLICK_BEEP_INDEX].itemName,\
                keyClickBeep, KEY_CLICK_BEEP_MIN, KEY_CLICK_BEEP_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                keyClickBeep = temp;
            }
            break;
        //按键长按蜂鸣时间
        case OLED_LEVEL2_KEY_LONG_BEEP_INDEX:
            {
                uint16_t temp = oled_set_val(oledMenuKey.item[OLED_LEVEL2_KEY_LONG_BEEP_INDEX].itemName,\
                keyLongBeep, KEY_LONG_BEEP_MIN, KEY_LONG_BEEP_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                keyLongBeep = temp;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED LED三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_led(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //LED1 & LED2
        case OLED_LEVEL2_LED1_INDEX:
        case OLED_LEVEL2_LED2_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuLedOption);
            switch(oledSelectLevel3)
            {
                //LED开启
                case OLED_LEVEL3_LED_ON_INDEX:
                    {
                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX && led1.mode == LED_MODE_SWITCH)
                        {
                            led1Switch = 1;
                        }
                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX && led2.mode == LED_MODE_SWITCH)
                        {
                            led2Switch = 1;
                        }
                    }
                    break;
                //LED关闭
                case OLED_LEVEL3_LED_OFF_INDEX:
                    {
                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX && led1.mode == LED_MODE_SWITCH)
                        {
                            led1Switch = 0;
                        }
                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX && led2.mode == LED_MODE_SWITCH)
                        {
                            led2Switch = 0;
                        }
                    }
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED OLED三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_oled(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //OLED dir
        case OLED_LEVEL2_OLED_DIR_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuOledDir);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //OLED正常模式
                case OLED_LEVEL3_OLED_DIR_NORMAL_INDEX:
                    oled_iic_send_data(0xC8, OLED_SEND_CMD);
                    oled_iic_send_data(0xA1, OLED_SEND_CMD);
                    oledDir = 0;
                    break;
                //OLED反转模式
                case OLED_LEVEL3_OLED_DIR_REVERSE_INDEX:
                    oled_iic_send_data(0xC0, OLED_SEND_CMD);
                    oled_iic_send_data(0xA0, OLED_SEND_CMD);
                    oledDir = 1;
                    break;
                default:
                    break;
            }
            break;
        //OLED light
        case OLED_LEVEL2_OLED_LIGHT_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuOledLight);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //OLED高亮度
                case OLED_LEVEL3_OLED_LIGHT_HIGH_INDEX:
                    oled_iic_send_data(0x81, OLED_SEND_CMD);
                    oled_iic_send_data(0xFA, OLED_SEND_CMD);
                    oledLightLevel = 0;
                    break;
                //OLED中亮度
                case OLED_LEVEL3_OLED_LIGHT_MID_INDEX:
                    oled_iic_send_data(0x81, OLED_SEND_CMD);
                    oled_iic_send_data(0x96, OLED_SEND_CMD);
                    oledLightLevel = 1;
                    break;
                //OLED低亮度
                case OLED_LEVEL3_OLED_LIGHT_LOW_INDEX:
                    oled_iic_send_data(0x81, OLED_SEND_CMD);
                    oled_iic_send_data(0x32, OLED_SEND_CMD);
                    oledLightLevel = 2;
                    break;
                default:
                    break;
            }
            break;
        //OLED cursor style
        case OLED_LEVEL2_OLED_CURSOR_STYLE_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuOledCursorStyle);
            if(oledSelectLevel3 != 0xFF)
            {
                oledCursorStyle = oledSelectLevel3;
            }
            break;
        //OLED refresh ms
        case OLED_LEVEL2_OLED_REFRESH_MS_INDEX:
            {
                uint16_t temp = oled_set_val(oledMenuOled.item[OLED_LEVEL2_OLED_REFRESH_MS_INDEX].itemName,\
                oledMainPageRefreshInterval, OLED_MAIN_PAGE_REFRESH_INTERVAL_MIN, OLED_MAIN_PAGE_REFRESH_INTERVAL_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                oledMainPageRefreshInterval = temp;
            }
            break;
        //OLED menu number
        case OLED_LEVEL2_OLED_MENU_NUMBER_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuOledMenuNumber);
        
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //显示编号
                case OLED_LEVEL3_OLED_MENU_NUMBER_SHOW_INDEX:
                    oledMenuNumberFlag = 0;
                    break;
                //不显示编号
                case OLED_LEVEL3_OLED_MENU_NUMBER_BLANK_INDEX:
                    oledMenuNumberFlag = 1;
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED RS485三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_rs485(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //RS485 mode
        case OLED_LEVEL2_RS485_MODE_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuRs485Mode);
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //RS485主动模式
                case OLED_LEVEL3_RS485_MODE_ACTIVE_INDEX:
                    rs485Mode = 0;
                    break;
                //RS485被动模式
                case OLED_LEVEL3_RS485_MODE_PASSIVE_INDEX:
                    rs485Mode = 1;
                    break;
                default:
                    break;
            }
            break;
        //RS485 ID
        case OLED_LEVEL2_RS485_ID_INDEX:
            if(oledSelectLevel2 == OLED_LEVEL2_RS485_ID_INDEX)
            {
                uint16_t temp = oled_set_val(oledMenuRs485.item[OLED_LEVEL2_RS485_ID_INDEX].itemName,\
                rs485Id, RS485_ID_MIN, RS485_ID_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                rs485Id = temp;
            }
            break;
        //RS485 baudrate
        case OLED_LEVEL2_RS485_BAUDRATE_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuRs485Baud);
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //9600
                case OLED_LEVEL3_RS485_BAUD_9600_INDEX:
                    rs485UsartBaudRate = 9600;
                    break;
                //19200
                case OLED_LEVEL3_RS485_BAUD_19200_INDEX:
                    rs485UsartBaudRate = 19200;
                    break;
                //38400
                case OLED_LEVEL3_RS485_BAUD_38400_INDEX:
                    rs485UsartBaudRate = 38400;
                    break;
                //57600
                case OLED_LEVEL3_RS485_BAUD_57600_INDEX:
                    rs485UsartBaudRate = 57600;
                    break;
                //74800
                case OLED_LEVEL3_RS485_BAUD_74800_INDEX:
                    rs485UsartBaudRate = 74800;
                    break;
                //115200
                case OLED_LEVEL3_RS485_BAUD_115200_INDEX:
                    rs485UsartBaudRate = 115200;
                    break;
                //230400
                case OLED_LEVEL3_RS485_BAUD_230400_INDEX:
                    rs485UsartBaudRate = 230400;
                    break;
                //460800
                case OLED_LEVEL3_RS485_BAUD_460800_INDEX:
                    rs485UsartBaudRate = 460800;
                    break;
                //500000
                case OLED_LEVEL3_RS485_BAUD_500000_INDEX:
                    rs485UsartBaudRate = 500000;
                    break;
                //576000
                case OLED_LEVEL3_RS485_BAUD_576000_INDEX:
                    rs485UsartBaudRate = 576000;
                    break;
                default:
                    break;
            }
            usart_enable(RS485_USART, FALSE);
            usart_init(RS485_USART, rs485UsartBaudRate, RS485_USART_DATA, RS485_USART_STOP);
            usart_enable(RS485_USART, TRUE);
            break;
        //RS485 active ms
        case OLED_LEVEL2_RS485_ACTIVE_MS_INDEX:
            {
                uint16_t temp = oled_set_val(oledMenuRs485.item[OLED_LEVEL2_RS485_ACTIVE_MS_INDEX].itemName,\
                rs485ActiveInterval, RS485_ACTIVE_INTERVAL_MIN, RS485_ACTIVE_INTERVAL_MAX);
                
                if(temp == 0xFFFF)
                    break;
                
                rs485ActiveInterval = temp;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED Step_Motor三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_step_motor(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Step motor mode
        case OLED_LEVEL2_STEP_MOTOR_MODE_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuStepMotorMode);
            
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //200
                case OLED_LEVEL3_STEP_MOTOR_MODE_FULL_INDEX:
                    step_motor_set_mode(FULL_STEP);
                    break;
                //400
                case OLED_LEVEL3_STEP_MOTOR_MODE_HALF_INDEX:
                    step_motor_set_mode(HALF_STEP);
                    break;
                //800
                case OLED_LEVEL3_STEP_MOTOR_MODE_QUARTER_INDEX:
                    step_motor_set_mode(QUARTER_STEP);
                    break;
                //1600
                case OLED_LEVEL3_STEP_MOTOR_MODE_EIGHTH_INDEX:
                    step_motor_set_mode(EIGHTH_STEP);
                    break;
                //3200
                case OLED_LEVEL3_STEP_MOTOR_MODE_SIXTEENTH_INDEX:
                    step_motor_set_mode(SIXTEENTH_STEP);
                    break;
                default:
                    break;
            }
            break;
        //Step motor speed
        case OLED_LEVEL2_STEP_MOTOR_SPD_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuStepMotorSpd);
            
            if(oledSelectLevel3 == 0xFF)
                break;
            
            step_motor_set_rotate_speed(oledSelectLevel3);
            
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED WS2812B三级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level3_ws2812b(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Mode
        case OLED_LEVEL2_WS2812B_MODE_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuWs2812bWorkMode);
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //跟随步进电机状态模式
                case OLED_LEVEL3_WS2812B_WORK_MODE_STEP_INDEX:
                    ws2812bMode = WS2812B_MODE_FOLLOW_STEP_MOTOR;
                    break;
                //跟随屏幕取色器模式
                case OLED_LEVEL3_WS2812B_WORK_MODE_PICKER_INDEX:
                    ws2812bMode = WS2812B_MODE_FOLLOW_PICKER;

                    break;
                default:
                    break;
            }
            break;
        //Stop color
        case OLED_LEVEL2_WS2812B_STOP_COLOR_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuWs2812bFixed);
            break;
        //Cw & Ccw Color
        case OLED_LEVEL2_WS2812B_CW_COLOR_INDEX:
        case OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX:
            oledSelectLevel3 = oled_dis_menu(&oledMenuWs2812bMode);
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //随机值
                case OLED_LEVEL3_WS2812B_MODE_RANDOM_INDEX:
                    {
                        oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX ? (ws2812bCwMode = 0) : (ws2812bCcwMode = 0);
                    }
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED LED四级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level4_led(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //LED1 & LED2
        case OLED_LEVEL2_LED1_INDEX:
        case OLED_LEVEL2_LED2_INDEX:
            {
                //匹配三级菜单编号
                switch(oledSelectLevel3)
                {
                    //LED模式
                    case OLED_LEVEL3_LED_MODE_INDEX:
                        {
                            oledSelectLevel4 = oled_dis_menu(&oledMenuLedMode);
                            
                            //匹配四级菜单编号
                            switch(oledSelectLevel4)
                            {
                                //LED呼吸灯模式
                                case OLED_LEVEL4_LED_MODE_BREATH_INDEX:
                                    {
                                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                                        {
                                            led_set_mode(&led1, LED_MODE_BREATH);
                                        }
                                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                                        {
                                            led_set_mode(&led2, LED_MODE_BREATH);
                                        }
                                    }
                                    break;
                                //LED闪烁模式
                                case OLED_LEVEL4_LED_MODE_BLINK_INDEX:
                                    {
                                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                                        {
                                            led_set_mode(&led1, LED_MODE_BLINK);
                                        }
                                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                                        {
                                            led_set_mode(&led2, LED_MODE_BLINK);
                                        }
                                    }
                                    break;
                                //LED开关模式
                                case OLED_LEVEL4_LED_MODE_SWITCH_INDEX:
                                    {
                                        if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                                        {
                                            led_set_mode(&led1, LED_MODE_SWITCH);
                                        }
                                        else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                                        {
                                            led_set_mode(&led2, LED_MODE_SWITCH);
                                        }
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    //LED呼吸步进
                    case OLED_LEVEL3_LED_BREATH_STEP_INDEX:
                        {
                            if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BREATH_STEP_INDEX].itemName,\
                                led1.breathStep, LED_BREATH_STEP_MIN, LED_BREATH_STEP_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_breath_step(&led1, temp);
                            }
                            else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BREATH_STEP_INDEX].itemName,\
                                led2.breathStep, LED_BREATH_STEP_MIN, LED_BREATH_STEP_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_breath_step(&led2, temp);
                            }
                        }
                        break;
                    //LED闪烁频率
                    case OLED_LEVEL3_LED_BLINK_FREQ_INDEX:
                        {
                            if(oledSelectLevel2 == OLED_LEVEL2_LED1_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BLINK_FREQ_INDEX].itemName,\
                                led1.blinkNum, LED_BLINK_TIME_MIN, LED_BLINK_TIME_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_blink_time(&led1, temp);
                            }
                            else if(oledSelectLevel2 == OLED_LEVEL2_LED2_INDEX)
                            {
                                uint16_t temp = oled_set_val(oledMenuLedOption.item[OLED_LEVEL3_LED_BLINK_FREQ_INDEX].itemName,\
                                led2.blinkNum, LED_BLINK_TIME_MIN, LED_BLINK_TIME_MAX);
                                
                                if(temp == 0xFFFF)
                                    break;
                                
                                led_set_blink_time(&led2, temp);
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED WS2812B四级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level4_ws2812b(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Stop color
        case OLED_LEVEL2_WS2812B_STOP_COLOR_INDEX:
            //匹配三级菜单编号
            switch(oledSelectLevel3)
            {
                //设置红色（Stop 和cw&ccw共用，Stop在第三极，cw&ccw为第四级，以cw&ccw为准命名）
                case OLED_LEVEL4_WS2812B_RED_INDEX:
                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_STOP_COLOR_INDEX)
                    {
                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_RED_INDEX].itemName,\
                        ws2812bStopRed, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                        
                        if(temp == 0xFFFF)
                            break;
                        
                        ws2812bStopRed = temp;
                    }
                    break;
                //设置绿色（Stop 和cw&ccw共用，Stop在第三极，cw&ccw为第四级，以cw&ccw为准命名）
                case OLED_LEVEL4_WS2812B_GREEN_INDEX:
                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_STOP_COLOR_INDEX)
                    {
                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_GREEN_INDEX].itemName,\
                        ws2812bStopGreen, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                        
                        if(temp == 0xFFFF)
                            break;
                        
                        ws2812bStopGreen = temp;
                    }
                    break;
                //设置蓝色（Stop 和cw&ccw共用，Stop在第三极，cw&ccw为第四级，以cw&ccw为准命名）
                case OLED_LEVEL4_WS2812B_BLUE_INDEX:
                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_STOP_COLOR_INDEX)
                    {
                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_BLUE_INDEX].itemName,\
                        ws2812bStopBlue, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                        
                        if(temp == 0xFFFF)
                            break;
                        
                        ws2812bStopBlue = temp;
                    }
                    break;
                default:
                    break;
            }
            
            break;
        //Cw & Ccw Color
        case OLED_LEVEL2_WS2812B_CW_COLOR_INDEX:
        case OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX:
            {
                //匹配三级菜单编号
                switch(oledSelectLevel3)
                {
                    //固定值
                    case OLED_LEVEL3_WS2812B_MODE_FIXED_INDEX:
                        if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                            ws2812bCwMode = 1;
                        else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                            ws2812bCcwMode = 1;
                        oledSelectLevel4 = oled_dis_menu(&oledMenuWs2812bFixed);
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
}


/**
 * @brief   OLED WS2812B五级菜单显示
 * @param   None
 * @retval  None
 * @note    None
*/
void oled_menu_level5_ws2812b(void)
{
    //匹配二级菜单编号
    switch(oledSelectLevel2)
    {
        //Cw & Ccw Color
        case OLED_LEVEL2_WS2812B_CW_COLOR_INDEX:
        case OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX:
            {
                //匹配三级菜单编号
                switch(oledSelectLevel3)
                {
                    //固定值
                    case OLED_LEVEL3_WS2812B_MODE_FIXED_INDEX:
                        {
                            //匹配四级菜单编号
                            switch(oledSelectLevel4)
                            {
                                //设置红色
                                case OLED_LEVEL4_WS2812B_RED_INDEX:
                                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_RED_INDEX].itemName,\
                                        ws2812bCwRed, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCwRed = temp;
                                    }
                                    else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_RED_INDEX].itemName,\
                                        ws2812bCcwRed, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCcwRed = temp;
                                    }
                                    break;
                                //设置绿色
                                case OLED_LEVEL4_WS2812B_GREEN_INDEX:
                                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_GREEN_INDEX].itemName,\
                                        ws2812bCwGreen, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCwGreen = temp;
                                    }
                                    else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_GREEN_INDEX].itemName,\
                                        ws2812bCcwGreen, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCcwGreen = temp;
                                    }
                                    break;
                                //设置蓝色
                                case OLED_LEVEL4_WS2812B_BLUE_INDEX:
                                    if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_BLUE_INDEX].itemName,\
                                        ws2812bCwBlue, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCwBlue = temp;
                                    }
                                    else if(oledSelectLevel2 == OLED_LEVEL2_WS2812B_CCW_COLOR_INDEX)
                                    {
                                        uint16_t temp = oled_set_val(oledMenuWs2812bFixed.item[OLED_LEVEL4_WS2812B_BLUE_INDEX].itemName,\
                                        ws2812bCcwBlue, WS2812B_RGB_VAL_MIN, WS2812B_RGB_VAL_MAX);
                                        
                                        if(temp == 0xFFFF)
                                            break;
                                        
                                        ws2812bCcwBlue = temp;
                                    }
                                    break;
                                default:
                                    break;
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            break;
        default:
            break;
    }
}
